package com.aplink.generic.pojo.controlspec.menu;

import java.io.Serializable;

import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;

import com.aplink.generic.GenericFragment;
import com.aplink.generic.constant.type.MenuShowAsActionType;
import com.aplink.generic.pojo.GenericObject;
import com.aplink.generic.pojo.controlspec.ControlSpec;
import com.aplink.generic.util.ResourcesHelper;
import com.aplink.generic.util.objectrule.Target;
import com.aplink.generic.util.objectrule.TargetCollection;
import com.aplink.generic.util.validation.LocationValidation;

public class MenuItemSpec extends ControlSpec implements Serializable {
    private static final long serialVersionUID = -7538144702581547261L;
    private String mContentData;
    private String mFormDesign;
    private GenericObject mGenericObject;
    private String mIcon;
    private String mID;
    private LocationValidation mLocationValidation;
    private int mOrderInCategory;
    private MenuShowAsActionType mShowAsActionType;
    private TargetCollection mTargetCollection;
    private String mTitle;

    public String getContentData() {
        return this.mContentData;
    }

    public int getContentDataID() {
        return ResourcesHelper.getRawIdByName(this.mContentData);
    }

    public String getFormDesign() {
        return this.mFormDesign;
    }

    public int getFormDesignID() {
        return ResourcesHelper.getRawIdByName(this.mFormDesign);
    }

    public GenericObject getGenericObject() {
        return this.mGenericObject;
    }

    public String getIcon() {
        return this.mIcon;
    }

    public int getIconID() {
        if (TextUtils.isEmpty(this.mIcon)) {
            return 0;
        }
        return ResourcesHelper.getDrawableIdByName(this.mIcon);
    }

    public String getID() {
        return this.mID;
    }

    @Override
    public int getIDValue() {
        return this.mID.hashCode();
    }

    public LocationValidation getLocationValidation() {
        return mLocationValidation;
    }

    public int getOrderInCategory() {
        return this.mOrderInCategory;
    }

    public MenuShowAsActionType getShowAsActionType() {
        return this.mShowAsActionType;
    }

    public TargetCollection getTargetCollection() {
        return this.mTargetCollection;
    }

    public String getTitle() {
        return this.mTitle;
    }

    public void linkToNextPage(final GenericFragment genericFragment)
            throws InstantiationException, IllegalAccessException,
            ClassNotFoundException, NameNotFoundException {
        final Target targetActivity = this.mTargetCollection
                .getTargetClass(this.mGenericObject);
        genericFragment.startActivity(targetActivity.getTargetClass(),
                targetActivity.getPassingValue(), this.mGenericObject);
    }

    public void setContentData(final String contentData) {
        this.mContentData = contentData;
    }

    public void setFormDesign(final String formDesign) {
        this.mFormDesign = formDesign;
    }

    public void setGenericObject(final GenericObject genericObject) {
        this.mGenericObject = genericObject;
    }

    public void setIcon(final String icon) {
        this.mIcon = icon;
    }

    public void setID(final String tag) {
        this.mID = tag;
    }

    public void setLocationValidation(
            final LocationValidation locationValidation) {
        mLocationValidation = locationValidation;
    }

    public void setOrderInCategory(final int orderInCategory) {
        this.mOrderInCategory = orderInCategory;
    }

    public void setShowAsActionType(final MenuShowAsActionType showAsActionType) {
        this.mShowAsActionType = showAsActionType;
    }

    public void setTargetCollection(final TargetCollection targetCollection) {
        this.mTargetCollection = targetCollection;
    }

    public void setTitle(final String title) {
        this.mTitle = title;
    }
}
